package com.swotxu.mall.search.controller;

import com.swotxu.common.exception.BizCodeEnum;
import com.swotxu.common.to.es.SkuESModel;
import com.swotxu.common.utils.R;
import com.swotxu.mall.search.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @Date: 2021/1/16 21:29
 * @Author: swotXu
 */
@Slf4j
@RestController
@RequestMapping("/search")
public class ElasticSaveController {

    @Autowired
    private ProductService productService;
    /**
     * 商品上架
     * @param skuESModelList
     * @return
     */
    @PostMapping("/product/up")
    public R productStatusUp(@RequestBody List<SkuESModel> skuESModelList) {
        boolean isOk = false;
        try {
            isOk = productService.productStatusUp(skuESModelList);
        } catch (IOException e) {
            log.error("商品上架错误！", e);
        }
        return isOk? R.ok() : R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION);
    }
}
